import { payrollPeople } from '../../api/pay'
Page({
    data: {
        id: '',
        pageNum: 0,
        list: [],
        notNext: false,
        searchText: '',
    },
    onLoad: function (options) {
        this.setData({
            id: options.id
        })
        this.getData()
    },
    searchWorker(event){
        this.setData({
            searchText: event.detail.value,
            pageNum: 0,
            list: [],
            notNext: false
        })
        this.getData()
    },
    getData() {
        console.log(this.data.notNext)
        if(this.data.notNext){
            return
        }
        this.setData({
            pageNum: this.data.pageNum + 1
        })
        payrollPeople({
            stubId: this.data.id,
            pageNum: this.data.pageNum,
            pageSize: 20,
            searchText: this.data.searchText
        }).then(res=>{
            res.list.map(item=>{
                item.userName = item.userName + item.idCardNo.slice(-4)
                console.log( item.userName)
                return item
            })
            this.data.list.push(...res.list)
            this.setData({
                list: this.data.list,
                notNext: !res.hasNextPage
            })
        })
    },
    goDetail(event){
        console.log(event)
        wx.navigateTo({
            url: '/packagePay/pages/payroll-detail/payroll-detail?id='+event.currentTarget.dataset.id,
        })
    }
});